<template>
	<div>
		<van-nav-bar title="我的请求"></van-nav-bar>
		<div>
			<van-pull-refresh v-model="flashingOrder" @refresh="flashOrder">
				<van-list v-model:loading="loadingNewOrder" :finished="noMoreOrder" finished-text="没有更多了" @load="loadNewOrder">
					<van-cell v-for="(order,key) in orderList" :key="key">
						<MyOfferCell :data="order" :openPrePayPage="openPrePayPage"></MyOfferCell>
					</van-cell>
				</van-list>
			</van-pull-refresh>
		</div>
		<van-popup  v-model:show="prepayPageShow" position="right" :style="{ width: '100%', height: '100%' }" closeable
			close-icon="arrow-left" close-icon-position="top-left" lazy-render>
			<div>
				<OfferOrderPrePayPage :data="prepayPageData" :orderOffer="orderOffer"></OfferOrderPrePayPage>
			</div>
		</van-popup>
	</div>
</template>

<script>
	import url from '@/assets/url.json';
	import MyOfferCell from '@/components/units/MyOfferCell.vue';
	import OfferOrderPrePayPage from '@/components/pages/OfferOrderPrePayPage';
	
	import {

		showNotify
	} from 'vant';
	
	export default {
		components:{
			MyOfferCell,
			OfferOrderPrePayPage
		},
		data() {
			return {
				noMoreOrder: false,
				flashingOrder: false,
				loadingNewOrder: false,
				orderList: [],
				page: 0,
				limit: 5,
				prepayPageShow: false,
				prepayPageData: {
					sellerName:'卖家用户名',
					goodName: '商品名',
					price: '648.66',
					number: 1,
					oid: '',
					id:'',
					statu:'已支付',
					time:'2023-4-23',
					imgSrc: '',
					headImgSrc :'',
					money:""
				},
				orderOffer: {}
			}
		},
		methods:{
			
			flashOrder(){
				this.page=0;
				this.orderList=[];
				this.noMoreOrder=false;
				this.pushOrder();
			},
			
			loadNewOrder(){
				// this.page+=1;
				this.pushOrder();
			},
			
			pushOrder(){
				this.page+=1;
				this.$axios({
					url:url.ip+'/api-offer'+'/offer/mine',
					method:'GET',
					params:{
						page: this.page,
						limit: this.limit,
					},
					headers:{
						token: this.$cookies.get('token'),
					}
				}).then((res)=>{
					console.log(res);
					if(res.data.code!==0){
						this.noMoreOrder=true;
						showNotify({ type: 'danger', message: res.data.message });
					}else{
						console.log(res.data.data);
						if(res.data.data.length<=0){
							this.noMoreOrder=true;
						}else{
							for(let key in res.data.data){
								this.orderList.push(res.data.data[key]);
							}
						}
					}
					this.loadingNewOrder=false;
					this.flashingOrder=false;
				}).catch(()=>{
					this.loadingNewOrder=false;
					this.flashingOrder=false;
					this.noMoreOrder=true;
					showNotify({ type: 'danger', message: "网络错误或未登录" });
				})
			},
			changePriceType(price) {
				let str = price;
				let numberPrice = Number.parseInt(str);
				if (numberPrice < 10) {
					str = '00' + str;
				} else {
					if (numberPrice < 100) {
						str = '0' + str;
					}
				}
			
				let arr = str.split('');
				arr.splice(-2, 0, '.');
				str = arr.join('');
				return str;
			},
			openPrePayPage(data){
				console.log(data);
				d.price = this.changePriceType(data.offer.price);
				let d = this.prepayPageData;
				d.sellerName=data.offer.user.userName;
				d.goodName=data.offer.title;
				d.statu = '未支付';
				d.time = data.offer.startTime;
				d.oid = data.offer.id;
				d.id = data.id;
				d.imgSrc = data.offer.imgSrc;
				d.money = d.price;
				this.orderOffer=data;
				this.prepayPageShow=true;
			}
		}
	}
</script>

<style>
</style>